package com.example.smartagrisys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.smartagrisys.entity.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 订单项Mapper接口
 */
@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItem> {

    /**
     * 计算产品的销售数量总和
     *
     * @param productId 产品ID
     * @return 销售数量总和
     */
    @Select("SELECT IFNULL(SUM(quantity), 0) FROM order_item WHERE product_id = #{productId}")
    Integer selectSumQuantity(@Param("productId") Long productId);
} 